import React, {useEffect} from 'react';
import {useAppDispatch} from "@/hooks";
import {getFindByParentIdAysnc, useSelectDict} from "@/store/slice/dict";
import {Table} from "antd";

function Dict() {
    const dispatch = useAppDispatch();
    const {dictList, loading} = useSelectDict();
    useEffect(() => {
        dispatch(getFindByParentIdAysnc(1))
    }, [])
    return (
        <div>
            <Table
                loading={loading}
                columns={[
                    {
                        title: "名称",
                        dataIndex: "name",
                    },
                    {
                        title:"编码",
                        dataIndex:"dictCode"
                    },
                    {
                        title:"值",
                        dataIndex:"value"
                    },
                    {
                        title:"创建时间",
                        dataIndex:"createTime"
                    }
                ]}
                //不显示分页
                pagination={false}
                //唯一表示
                rowKey={"id"}
                //数据数组
                dataSource={dictList}
                // 配置展开属性
                expandable = {{
                    onExpand(expanded, record) {
                        // expanded:是布尔值，true 点开，false 折叠
                        // record:行信息
                        // console.log(expanded, record)
                        if (expanded) {
                            dispatch(getFindByParentIdAysnc(record.id))
                        }
                    }
                }}
            >

            </Table>
        </div>
    );
}

export default Dict;